/*
 * ArchConfig.c
 *
 *  Created on: 21/09/2011
 *      Author: utn_so
 */
#include "RAID.h"

int cargarLogYArchivoConfiguracion(t_raid *pRaid){

	char *buffer;
	int port;

	if((buffer=fileio_openfile("RaidConfig"))==NULL){
		logMessage(LOG_ERR,"No se creo el archivo configuracion");
		printf("No se creo el archivo configuracion");

		return 0;
		//Error al abrir el archivo
	}
	pRaid->configArch = (t_config*)malloc(sizeof(t_config));
	logMessage(LOG_INFO,"Procesando archivo de configuracion....");

	/*PuertoPPD*/
	if(!(pRaid->configArch->puertoPPD=config_loader_getInt(buffer,"PuertoPPD:"))){
		logMessage(LOG_ERR,"Falta puertoPPD");
		return 0;
	}
	logMessage(LOG_INFO, "Puerto puertoPPD: %d",pRaid->configArch->puertoPPD);

	/*ConsolaFlag*/
	if(!(pRaid->configArch->consolaFlag=config_loader_getInt(buffer,"ConsolaFlag:"))){
		if(pRaid->configArch->consolaFlag){
			logMessage(LOG_INFO,"consolaFlag: Activado");
		}else{
			logMessage(LOG_INFO,"consolaFlag: Desactivado");
		}
	}

	/*levelLog*/
	if(!(pRaid->configArch->levelLog=config_loader_getInt(buffer,"LevelLog:"))){
		logMessage(LOG_ERR,"Falta levelLog");
		return 0;
	}
	logMessage(LOG_INFO, "levelLog: %d",pRaid->configArch->levelLog);

	/*tamConexiones*/
	if(!(pRaid->configArch->tamConexiones=config_loader_getInt(buffer,"TamConexiones:"))){
		logMessage(LOG_ERR,"Falta tamConexiones");
		return 0;
	}
	logMessage(LOG_INFO, "tamConexiones: %d",pRaid->configArch->tamConexiones);

	/*puertoSendPPD*/
	if(!(pRaid->configArch->puertoSendPPD=config_loader_getInt(buffer,"PuertoSendPPD:"))){
		logMessage(LOG_ERR,"Falta puertoSendPPD");
		return 0;
	}
	logMessage(LOG_INFO, "Puerto puertoSendPPD: %d",pRaid->configArch->puertoSendPPD);

	/*PuertoPFS*/
	if(!(pRaid->configArch->puertoPFS=config_loader_getInt(buffer,"PuertoPFS:"))){
		logMessage(LOG_ERR,"Falta puertoPFS");
		return 0;
	}
	logMessage(LOG_INFO, "Puerto puertoPFS: %d",pRaid->configArch->puertoPFS);

	/*PuertoPFSPoll*/
	if(!(pRaid->configArch->puertoPFSPoll=config_loader_getInt(buffer,"PuertoPFSPoll:"))){
		logMessage(LOG_ERR,"Falta puertoPFSPoll");
		return 0;
	}
	logMessage(LOG_INFO, "Puerto puertoPFSPoll: %d",pRaid->configArch->puertoPFSPoll);

	/*IP*/
	if(!(pRaid->configArch->ip=config_loader_getString(buffer,"Ip:"))){
		logMessage(LOG_ERR,"Flata mi ip");
		return 0;
	}

	logMessage(LOG_INFO,"La ip es: %s",pRaid->configArch->ip);

	return 1;
}
